package com.example.fw.datamapping;

//Class for describing representation of a contact in the table on the main page

public class ContactLine implements Comparable<ContactLine>{
	public String fName;
	public String lName;
	public String email;
	public String phone;
	public Boolean isPrimaryAddSet;
	
	public ContactLine(){
		this.fName = "";
		this.lName = "";
		this.email = "";
		this.phone = "";
		this.isPrimaryAddSet = false;
	}
	
	public ContactLine(String fName, String lName, String email, String phone, Boolean isPrimaryAddSet){
		if (fName != null) {
			this.fName = fName;
		} else {this.fName = "";}
		if (lName != null) {
			this.lName = lName;
		} else {this.lName = "";}
		if (email != null) {
			this.email = email;
		} else {this.email = "";}
		if (phone != null) {
			this.phone = phone.replaceAll("\\s","");
		} else {this.phone = "";}
		if (isPrimaryAddSet != null) {
			this.isPrimaryAddSet = isPrimaryAddSet;
		} else {this.isPrimaryAddSet = false;}
	}

	@Override
	public String toString() {
		return "ContactLine [fName=" + fName + ", lName=" + lName + ", email="
				+ email + ", phone=" + phone + ", isPrimaryAddSet="
				+ isPrimaryAddSet + "]";
	}
	
	@Override
	public int compareTo(ContactLine other) {
		int lNameCopmResult = this.lName.compareToIgnoreCase(other.lName);
		
		if (lNameCopmResult == 0){
			return this.fName.compareToIgnoreCase(other.fName);
		} else {
			return lNameCopmResult;
		}
	}

	@Override
	public int hashCode() {
		/*final int prime = 31;
		int result = 1;
		result = prime * result + ((email == null) ? 0 : email.hashCode());
		result = prime * result + ((fName == null) ? 0 : fName.hashCode());
		result = prime * result
				+ ((isPrimaryAddSet == null) ? 0 : isPrimaryAddSet.hashCode());
		result = prime * result + ((lName == null) ? 0 : lName.hashCode());
		result = prime * result + ((phone == null) ? 0 : phone.hashCode());
		return result;*/
		return 1;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ContactLine other = (ContactLine) obj;
		if (email == null) {
			if (other.email != null)
				return false;
		} else if (!email.equals(other.email))
			return false;
		if (fName == null) {
			if (other.fName != null)
				return false;
		} else if (!fName.equals(other.fName))
			return false;
		if (isPrimaryAddSet == null) {
			if (other.isPrimaryAddSet != null)
				return false;
		} else if (!isPrimaryAddSet.equals(other.isPrimaryAddSet))
			return false;
		if (lName == null) {
			if (other.lName != null)
				return false;
		} else if (!lName.equals(other.lName))
			return false;
		if (phone == null) {
			if (other.phone != null)
				return false;
		} else if (!phone.equals(other.phone))
			return false;
		return true;
	}
	
	
}
 
